palette: make palette conversion thread safe
authorEll <ell_se@yahoo.com>
Wed, 21 Jun 2017 17:53:08 +0000 (13:53 -0400)
committerEll <ell_se@yahoo.com>
Wed, 21 Jun 2017 18:45:43 +0000 (14:45 -0400)
commitaab1ef832fc61c5d21773eb23b17f2b906e0060e
treea34131bf6c6d4decb256d6e202f53a772ccb341f
parent4ac6c9b18b4c90432d82ed204f5fbd7bfd8dd74b
palette: make palette conversion thread safe

Conversion from RGBA u8 to an 8-bit palette format caches conversion
results in a hash table, belonging to the palette model.  Currently,
manipulation of the hash table is not thread safe -- when multiple
threads convert to the same palette format concurrently, the result
may be wrong.  In particular, there is a race condition when two
different colors that share the same hash are converted concurrently.

Fix this by changing the hash table layout, so that it can be
modified atomically.  We assume that aligned 32-bit writes are
atomic.

Note that the new layout is only suitable for palettes with up to
256 colors, but this is all we use the hash table for ATM anyway.

Add a regression test.
babl/babl-palette.c
tests/Makefile.am
tests/palette-concurrency-stress-test.c [new file with mode: 0644]